package com.lap.service.starter.autoconfigure;

import com.lap.service.starter.advice.RestBodyAdvice;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自动装载 增强类。
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
@AutoConfiguration
@ComponentScan("com.lap.service.starter")
public class ServiceAutoConfiguration {

  /**
   *
   *
   * <pre>
   * 默认扫描 com 包。(知识点: matchIfMissing=true ，表示不配置的时候也是有效，可以提高不配置时候也是有效，减少配置)
   * <ol>
   * <li>在 <b>application.yaml/properties</b> 添加一下配置</li>
   * {@code
   * rest:
   *   advice:
   *     enabled: false
   * }
   * <li>创建自己实现类:</li>
   * {@code
   * @RestControllerAdvice(basePackages = "您的包")
   * public class MyRestBodyAdvice extends RestBodyAdvice {
   *
   * }
   * }
   * </ol>
   * </pre>
   */
  @RestControllerAdvice(basePackages = "com")
  @ConditionalOnProperty(
      prefix = "rest.advice",
      name = "enabled",
      havingValue = "true",
      matchIfMissing = true)
  static class DefaultRestBodyAdvice extends RestBodyAdvice {}
}
